const request = require('./index')

module.exports = {

  // 获取tanent_token
  getToken: function (params) {
    return request({
      url: '/auth/v3/tenant_access_token/internal',
      method: 'post',
      headers: {
        "Content-Type": "application/json; charset=utf-8"
      },
      data: {
        "app_id": 'cli_a4cfedd98ef8d00e',
        "app_secret": '0ZWc1QY3NBzqaCcoqJN2PcQAY7qcdeIz'
      }
    })
  },

  // 发送消息
  sendMsg: function (token, chat_id, query) {
    return request({
      url: '/im/v1/messages',
      method: 'post',
      headers: {
        "Authorization": token,
        "Content-Type": "application/json; charset=utf-8"
      },
      params: {
        receive_id_type: "chat_id"
      },
      data: {
        "receive_id": chat_id,
        // 消息卡片类型
        "msg_type": "interactive",
        // 发送内容
        "content": `{\"elements\":[{\"tag\":\"div\",\"text\":{\"content\":\"${query.content}\",\"tag\":\"lark_md\"}}],\"header\":{\"template\":\"turquoise\",\"title\":{\"content\":\"${query.title}\",\"tag\":\"plain_text\"}}}`
      }

    })
  },

  // 获取机器人所在群id
  getChatId: function (token) {
    return request({
      url: '/im/v1/chats',
      method: 'get',
      headers: {
        "Authorization": token
      },
      params: {
        page_size: 20
      }
    })
  },

  // 获取open_id
  getOpenId: function (token, phone) {
    return request({
      url: '/contact/v3/users/batch_get_id',
      method: 'post',
      headers: {
        "Authorization": token,
        "Content-Type": "application/json; charset=utf-8"
      },
      data: {
        mobiles: [phone]
      },
      params: {
        user_id_type: 'open_id'
      }
    })
  },

  // 创建任务
  sendTask: function (token, data) {
    return request({
      url: '/task/v1/tasks',
      method: 'post',
      headers: {
        "Authorization": token,
        "Content-Type": "application/json; charset=utf-8"
      },
      params: {
        user_id_type: 'open_id'
      },
      data: data
    })
  }
}